package rdp.cmd.skill;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import rdp.RDPUtil;

public class CMDSkill {
    public boolean execute(CommandSender sender, String[] args) {
        boolean isAdmin = sender.hasPermission("minecraft");
        boolean isPlayer = sender instanceof Player;
        Player player = isPlayer ? (Player) sender : null;
        Player target = null;

        if (args.length == 1) {
            args = new String[]{"skill", "menu"};
        }
        if (getCmd(args[1]) == "menu") {
            if (isPlayer) {
                player.openInventory(getMenu());
                return true;
            } else
                args = new String[]{"skill", "help"};
        }
        if (getCmd(args[1]) == "help") {
            RDPUtil.SEND(sender, getHelp());
            return true;
        }
        switch (getCmd(args[1])) {
            case "list":
                break;
            case "learn":
                break;
            case "enable":
                break;
            case "disable":
                break;
            default:
                RDPUtil.SEND(sender, "§4指令不存在。");
        }
        return true;
    }

    private String getCmd(String str) {
        List<String[]> list = new ArrayList();
        list.add(new String[]{"?", "help"});
        list.add(new String[]{"!", "menu"});

        for (String[] strs : list) {
            if (RDPUtil.CHECK(str, strs))
                return strs[strs.length - 1];
        }
        return null;
    }

    private String[] getHelp() {
        return new String[]{
                "§b/rdp skill help§f - 获取技能指令组帮助。",
                "§b/rdp skill menu§f - 打开技能菜单。"
        };
    }

    private Inventory getMenu() {
        Inventory inv = Bukkit.createInventory(null, 54, "技能菜单");

        ItemStack blank = new ItemStack(Material.GLASS_PANE);
        ItemMeta blankIM = blank.getItemMeta();
        blankIM.setDisplayName("");
        blank.setItemMeta(blankIM);

        for (int i = 0; i < inv.getSize(); i++)
            inv.setItem(i, blank);

        Map exit = new HashMap() {{
            put("MATERIAL", Material.BARRIER);
            put("NAME", "§c返回 §f| §c帮助");
            put("LORE", new ArrayList<String>() {{
                add("§b左击§a返回主菜单");
                add("§b右击§a查看帮助");
            }});
            put("LEFT", "/rdp menu");
            put("RIGHT", "/rdp skill help");
        }};

        inv.setItem(inv.getSize()-1, RDPUtil.ITEM(exit));
        return inv;
    }

}
